package pts.salooner.ws;

import java.util.ArrayList;
import java.util.List;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

import pts.salooner.data.SaloonerVo;
import pts.salooner.data.dao.SaloonerDao;
import pts.salooner.ws.exception.SaloonerWSException;
import pts.salooner.ws.filter.SaloonerWSFilter;
import pts.salooner.ws.model.Salooner;

@WebService
public class SaloonerWS {

	private SaloonerDao dao = new SaloonerDao();

//	@WebMethod
//	public Salooner findSalooner(@WebParam(name = "id") Integer id)
//			throws SaloonerWSException {
//
//		if (id == null || id.intValue() == 0) {
//			throw new SaloonerWSException("Salooner's ID not specified");
//		}
//
//		SaloonerVo vo = dao.getById(id);
//		return vo != null ? new Salooner(vo) : new Salooner();
//	}

//	@WebMethod
//	public List<Salooner> findAll() {
//		List<SaloonerVo> vos = dao.getAll();
//		List<Salooner> salooners = new ArrayList<Salooner>();
//		for (SaloonerVo vo : vos) {
//			salooners.add(new Salooner(vo));
//		}
//
//		return salooners;
//	}

	@WebMethod
	public List<Salooner> find(
			@WebParam(name = "wsfilter") SaloonerWSFilter filter)
			throws SaloonerWSException {

		List<Salooner> salooners = new ArrayList<Salooner>();
		if (filter != null) {

			List<SaloonerVo> vos = dao.get(filter.getDaoFilter());

			for (SaloonerVo vo : vos) {
				salooners.add(new Salooner(vo));
			}
		}

		return salooners;
	}

}
